package com.ita.factory;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;

import org.apache.activemq.ActiveMQConnectionFactory;

public class MQConnFactory {

	private static Connection con;

//	static {
//		try {
//			ConnectionFactory factory = new ActiveMQConnectionFactory(
//					"tcp://10.222.29.155:61616");
//			con = factory.createConnection();
//		} catch (JMSException e) {
//			e.printStackTrace();
//		}
//	}

	private MQConnFactory() {

	}

	public static Connection getConnection() {

//		if (con == null) {
//			ConnectionFactory factory = new ActiveMQConnectionFactory(
//					"tcp://10.222.29.155:61616");
//			try {
//				con = factory.createConnection();
//			} catch (JMSException e) {
//				e.printStackTrace();
//			}
//		}
		return con;
	}

	public static void close() {

		try {
			con.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

	public static void open() {

		if (con == null) {
			con = getConnection();
		}
		try {
			con.start();
		} catch (JMSException e) {
			e.printStackTrace();
		}

	}

}
